package com.zhika.zishi.util;

import android.app.Activity;

import com.zhika.zishi.activity.BaseActivity;

import java.util.ArrayList;

/**
 * Created by Michael on 2015/4/3.
 * 处理Activity,方便管理
 */
public class ActivityCollector {

    //定义一个收集activity的list
    public static ArrayList<Activity> activityList = new ArrayList<>();

    /**
     * 添加activity到list
     * @param activity
     */
    public static void addActivity(Activity activity){
        activityList.add(activity);
    }

    /**
     * 从list中移除activity,并销毁
     * @param activity
     */
    public static void remoteActivity(Activity activity){
        activityList.remove(activity);
        activity.finish();
    }

    /**
     * 销毁所有的activity
     */
    public static void finishAllActivity(){
        for (Activity activity:activityList){
            if (!activity.isFinishing()){
                activity.finish();
            }
        }
        activityList.clear();
    }
}

